package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import com.msstudio.midlets.MSCMIDlet;
import java.util.Calendar;
import java.util.Vector;
import javax.microedition.lcdui.*;

public class HistoryMsg
    implements CommandListener
{//��ʷ��Ϣ�ࣻ

    protected Command cmdBack;
    protected Command cmdNext;
    private static final int C_MaxHistoryNum = 100;
    private int iComMsgNum;
    private int iCurMsgIndex;
    private long iUIN;
    private Vector vComMsg;

    public HistoryMsg()
    {
        cmdBack = null;
        cmdNext = null;
        iComMsgNum = 0;
        iCurMsgIndex = 0;
        iUIN = 0L;
        vComMsg = new Vector();
    }

    public void init()
    {
        cmdBack = new Command(MSCMIDlet.multiLang.sCancel, 2, 3);
        cmdNext = new Command(MSCMIDlet.multiLang.sNext, 1, 1);
    }

    public int getComMsgNum()
    {
        return iComMsgNum;
    }

    public void appendComSendMsg(String s, String s1)
    {
        Calendar calendar = Calendar.getInstance();
        StringBuffer stringbuffer = new StringBuffer();
        stringbuffer.append(calendar.get(2) + 1).append("/").append(calendar.get(5)).append(" ").append(calendar.get(11)).append(":").append(PkgTools.To2Str(calendar.get(12))).append(":").append(PkgTools.To2Str(calendar.get(13))).append("\n").append(MSCMIDlet.httpPoster.GetSelfUIN()).append(":").append(s1);
        appendComMsg(s, stringbuffer.toString());
    }

    public void appendComRecMsg(String s, String s1)
    {
        appendComMsg(s, s1);
    }

    private void appendComMsg(String s, String s1)
    {
        if(iComMsgNum == 100)
        {
            vComMsg.removeElementAt(1);
            vComMsg.removeElementAt(0);
            iComMsgNum--;
        }
        vComMsg.addElement(s);
        vComMsg.addElement(s1);
        iComMsgNum++;
    }

    private String getComMsgByUIN(long l, boolean flag, boolean aflag[])
    {
        int i = 0;
        boolean flag1 = false;
        if(flag)
            i = iCurMsgIndex + 2;
        else
            iCurMsgIndex = 0;
        aflag[0] = false;
        for(; i < vComMsg.size(); i += 2)
        {
            if(!((String)vComMsg.elementAt(i)).equals(Long.toString(l)))
                continue;
            if(!flag1)
            {
                iCurMsgIndex = i;
                flag1 = true;
                continue;
            }
            aflag[0] = true;
            break;
        }

        if(flag1)
            return (String)vComMsg.elementAt(iCurMsgIndex + 1);
        else
            return null;
    }

    private void readComMsg(long l)
    {
        boolean aflag[] = {
            false
        };
        String s = getComMsgByUIN(l, false, aflag);
        if(s == null)
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sHistory, MSCMIDlet.multiLang.sHistoryIsNull, this, cmdBack, null);
        else
        if(aflag[0])
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sHistory, s, this, cmdNext, cmdBack);
        else
            MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sHistory, s, this, cmdBack, null);
    }

    private void nextComMsg()
    {
        boolean aflag[] = {
            false
        };
        String s = getComMsgByUIN(iUIN, true, aflag);
        if(s != null)
            if(aflag[0])
                MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sHistory, s, this, cmdNext, cmdBack);
            else
                MSCMIDlet.instance.showMessage(MSCMIDlet.multiLang.sHistory, s, this, cmdBack, null);
    }

    public void show(long l)
    {
        iUIN = l;
        readComMsg(l);
    }

    public void commandAction(Command command, Displayable displayable)
    {//����?��
        try
        {
            if(command == cmdBack)
                MSCMIDlet.mainForm.show();
            else
            if(command == cmdNext)
                nextComMsg();
        }
        catch(Exception exception) { }
    }
}
